package cn.cboard.dao.sql;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import cn.cboard.dao.TopicDao;
import cn.cboard.database.Query;
import cn.cboard.model.ForumThread;
import cn.cboard.model.ForumTopic;

@SuppressWarnings("unchecked")
public class TopicDaoSql implements TopicDao{
	private final static Logger logger = Logger.getLogger(TopicDaoSql.class);
	private Query query = null;

	public TopicDaoSql(Query query) {
		this.query = query;		
	}

	
	public ForumThread getThread(Long threadId) {
		logger.debug("[boardmx]--> entry Thread Id:" + threadId);
		String sqlquery="SELECT * FROM forumthreads where threadid=?";
		List queryParams = new ArrayList();
		queryParams.add(threadId);
		ForumThread forumThread = null;
		
		try {
			forumThread = (ForumThread) query.queryMapper(queryParams, sqlquery, new ThreadMapper());
		} catch (Exception e) {
			logger.error(e);
		}
		
		return forumThread;
	}

	public ForumTopic getToic(Long topicId) {
		logger.debug("[boardmx]--> entry ForumTopic Id:" + topicId);
		String sqlquery="select * from forumtopics where topicid=?";
		List queryParams = new ArrayList();
		queryParams.add(topicId);
		ForumTopic topic = null;
		
		try {
			topic = (ForumTopic) query.queryMapper(queryParams, sqlquery, new TopicMapper());
		} catch (Exception e) {
			logger.error(e);
		}
		
		return topic;
	}

}
